import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/widgets.dart';

class NestedScrollViewDemo extends StatefulWidget {
  const NestedScrollViewDemo({Key? key}) : super(key: key);

  @override
  State<NestedScrollViewDemo> createState() => _NestedScrollViewDemotate();
}

class _NestedScrollViewDemotate extends State<NestedScrollViewDemo> with SingleTickerProviderStateMixin {

  late TabController tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 要加 SingleTickerProviderStateMixin
    tabController = new TabController(length: 3, vsync: this);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(
      //   title:const Text("滑动布局NestedScrollView与SliverAppBar使用分析") ,
      //   centerTitle: true,
      // ),
      // 
      body: NestedScrollView(
        headerSliverBuilder: (context, innerBoxIsScrolled) {
          return [
            SliverAppBar(
              // 标题
              // title: Text("标题"),
              // leading: Icon(Icons.home),
              // actions: [
              //   Icon(Icons.share),
              // ],
              // true  sliverAppBar 不会滑动
              pinned: true,
              floating: true, // 是否随着滑动隐藏标题
              // SliverAppBar 展开高度
              expandedHeight: 160,
              flexibleSpace: FlexibleSpaceBar(
                title: Text("FlexibleSpaceBar title"),
                centerTitle: true,
                background: Container(
                  color: Colors.blue[300],
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        height: 160,
                        child: Image.network("https://img-blog.csdnimg.cn/20210324100419204.png",fit: BoxFit.fill,height: 160,))
                    ],
                  ),
                ),
              ),
              bottom: TabBar(
                controller: tabController,
                tabs: [
                  new Tab(text: "标签一"),
                  new Tab(text: "标签二"),
                  new Tab(text: "标签三"),
                ],
              ),

            )
          ];
        },
        body:TabBarView(
          controller: tabController,
          children: [
            SingleChildScrollView(child: Container(alignment: Alignment.bottomLeft,child: Text("这是第一个页面"),height: 1000,)),
            Text("这是第二个页面", style: TextStyle(color: Colors.red),),
            Text("这是第三个页面", style: TextStyle(color: Colors.blue),),

        ])

        
      ),
    );
     
   
    
  }
  

}